
// <copyright file="GlobalSettings.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The global settings.
// </summary>

namespace SubhadraSolutions.Sharp.Utils
{
    using System;

    using SubhadraSolutions.Sharp.Utils.Diagnostics;

    /// <summary>
    /// The global settings.
    /// </summary>
    public sealed class GlobalSettings
    {
        #region Static Fields

        /// <summary>
        /// The instance.
        /// </summary>
        private static readonly GlobalSettings InstanceObject = new GlobalSettings();

        #endregion Static Fields

        #region Fields

        /// <summary>
        /// The is service.
        /// </summary>
        private bool _isService;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Prevents a default instance of the <see cref="GlobalSettings"/> class from being created.
        /// </summary>
        private GlobalSettings()
        {
            this.UseUtcTime = false;
            this.Environment = "DEV";
            this.MachineName = System.Environment.MachineName;
        }

        #endregion Constructors and Finalizers

        #region Public Properties

        /// <summary>
        /// Gets the instance.
        /// </summary>
        public static GlobalSettings Instance
        {
            get
            {
                return InstanceObject;
            }
        }

        /// <summary>
        /// Gets or sets the application name.
        /// </summary>
        public string ApplicationName { get; set; }

        /// <summary>
        /// Gets the current date time.
        /// </summary>
        public DateTime CurrentDateTime
        {
            get
            {
                return this.UseUtcTime ? DateTime.UtcNow : DateTime.Now;
            }
        }

        /// <summary>
        /// Gets or sets the environment.
        /// </summary>
        public string Environment { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether is service.
        /// </summary>
        public bool IsService
        {
            get
            {
                return this._isService;
            }

            set
            {
                this._isService = value;
                if (!value && this.ApplicationName == null)
                {
                    this.ApplicationName = ProcessHelper.CurrentProcessInstanceName;
                }
            }
        }

        /// <summary>
        /// Gets the machine name.
        /// </summary>
        public string MachineName { get; private set; }

        /// <summary>
        /// Gets or sets a value indicating whether use utc time.
        /// </summary>
        public bool UseUtcTime { get; set; }

        #endregion Public Properties
    }
}
